package com.mofang.powerdekorhelper.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.mofang.powerdekorhelper.R;
import com.mofang.powerdekorhelper.model.JHelpAndFeedback;

import java.util.List;

/**
 * Created by luofei on 2016/9/5 0005.
 */
public class MyExpandableListAdapter extends BaseExpandableListAdapter {

    private Context mContext;
    private LayoutInflater mInflater;
    public List<JHelpAndFeedback.HelpAndFeedbackResult> helpAndFeedbackList;

    public MyExpandableListAdapter(Context mContext, List<JHelpAndFeedback.HelpAndFeedbackResult> helpAndFeedbackList) {
        this.mContext = mContext;
        this.helpAndFeedbackList = helpAndFeedbackList;
        mInflater = LayoutInflater.from(mContext);
    }

    @Override
    public int getGroupCount() {
        return helpAndFeedbackList.size();
    }

    @Override
    public int getChildrenCount(int i) {
        return helpAndFeedbackList.get(i).getQuestions().size();
    }

    @Override
    public Object getGroup(int i) {
        return helpAndFeedbackList.get(i);
    }

    @Override
    public Object getChild(int i, int i1) {
        return helpAndFeedbackList.get(i).getQuestions().get(i);
    }

    @Override
    public long getGroupId(int i) {
        return i;
    }

    @Override
    public long getChildId(int i, int i1) {
        return i1;
    }

    @Override
    public boolean hasStableIds() {
        return false;
    }

    @Override
    public View getGroupView(int pisition, boolean isExpanded, View view, ViewGroup viewGroup) {

        view = mInflater.inflate(R.layout.help_and_feedback_list_item_layout, null);
        TextView textView = (TextView) view.findViewById(R.id.help_and_feedback_list_item_layout_tv);
        ImageView imageView = (ImageView) view.findViewById(R.id.brand_expand_list_item_group_flag);

        textView.setText(helpAndFeedbackList.get(pisition).getQuestion_type());

        if (isExpanded) {
            imageView.setImageResource(R.mipmap.error_up_icon);
        } else {
            imageView.setImageResource(R.mipmap.arrow_right_gray);
        }

        return view;
    }

    @Override
    public View getChildView(int position1, int pisition, boolean b, View view, ViewGroup viewGroup) {

        view = mInflater.inflate(R.layout.help_and_feedback_list_item_layout2, null);
        TextView textView = (TextView) view.findViewById(R.id.help_and_feedback_list_item_layout_tv2);
        JHelpAndFeedback.HelpAndFeedbackResult.HelpAndFeedback helpAndFeedback = helpAndFeedbackList.get(position1).getQuestions().get(pisition);
        textView.setText(helpAndFeedback.getTitle());
        view.setTag(helpAndFeedback);

        return view;
    }

    @Override
    public boolean isChildSelectable(int i, int i1) {
        return true;
    }
}
